package com.platform.destiny.config;

import cn.hutool.core.collection.CollUtil;
import com.platform.destiny.dto.UserDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户鉴权
 * @Description
 * @Author kaiyang
 * @Date 2024-02-01 12:55 PM
 */

@Slf4j
@Service("ss")
public class PermissionService {

    /** 验证用户是否具备某权限 @param permission 权限字符串 @return 用户是否具备某权限 */
    public boolean hasPermi(String permission) {
        UserDto dto = (UserDto) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        List<String> permissions = dto.getPermissions();
        boolean contains = CollUtil.contains(permissions, permission);
        log.info("permission {}", contains);
        return contains;
    }


}
